import java.util.HashSet;

public class NumJewelsInStones {
    public static int numJewelsInStones(String jewels, String stones) {
        HashSet<Character> jewelsSet = new HashSet<>();
        //设置一个计数器
        int result = 0;

        //遍历宝石把宝石放入Set集合之中
        for(int i = 0; i<jewels.length();i++) {
            jewelsSet.add(jewels.charAt(i));
        }

        //遍历石头，看每一个石头是不是在宝石之中
        for(int j = 0;j < stones.length();j++) {
            if (jewelsSet.contains(stones.charAt(j))) {
                result++;
            }
        }

        //代码走到这里，说明已经统计完了石头之中，宝石的个数
        return result;
    }

    public static void main(String[] args) {
          String jewels = "z";
          String stones = "ZZ";

        System.out.println(numJewelsInStones(jewels,stones));
    }
}
